/**
 * Created by 刘玉波 on 2016/1/26.
 */
define(['angular', 'app.directives','services/common/base','services/common/user'], function (angular, directives) {
    'use strict';
    directives.directive("relogin",['$q','User','MessageBox','WindowType','MessageType',function($q,User,MessageBox,WindowType,MessageType){
        return {
            restrict: 'E',
            scope: {},
            replace: true,
            templateUrl : "/app/partial/common/relogin.html",
            link : function($scope,$element,$attr){
                $scope.userName ="";
                $scope.password = "";


                $scope.onLogin = function(){
                    if(!$scope.password || $scope.length < 1){
                        MessageBox.show("请填写密码", WindowType.title, MessageType.error);
                        return false;
                    }



                    User.login({username : $scope.userName,password : $scope.password},function(result){
                        $(document).trigger('reloginSuccess',result);
                    }, function(error){
                        MessageBox.show(error.message, WindowType.title, MessageType.error);
                    });

                };

                $scope.onBack = function(){
                    window.location.href= "/";
                };
            }
        }
    }]);
});